import Vue from 'vue'
import Storage from 'vue-ls'
import 'normalize.css/normalize.css' // a modern alternative to CSS resets
import ElementUI from 'element-ui'
import './assets/styles/index.scss' // global css
import './assets/icons/' // icon
import './assets/icons/iconfont' // icon
import App from './App'
import store from './store/'
import router from './router'
import './permission' // permission control
import Clipboard from 'v-clipboard'
// 头部标签组件
import VueMeta from 'vue-meta'
import promiseFinally from 'promise.prototype.finally';
import AllComponents from '@/components';
import md5 from 'js-md5';
import { getToken } from '@/utils/auth'

import echarts from 'echarts/lib/echarts';//导入主库

import {
  SETTING_ELEMENT_SIZE,
  SETTING_SIDEBAR_STATUS,
  SETTING_THEME_COLOR,
  SETTING_SIDE_THEME,
  SETTING_TAGS_VIEW,
  SETTING_FIXED_HEADER,
  SETTING_SIDEBAR_LOGO,
  SETTING_DYNAMIC_TITLE
} from "@/store/sys-constant";

import {initCurTheme} from '@/utils/themeUtil';

promiseFinally.shim();

const defaultSettings = require('./settings.js')
// 全局组件挂载
Vue.use(Storage, defaultSettings.storageOptions)
Vue.use(VueMeta)
Vue.prototype.md5 = md5
Vue.use(AllComponents)
Vue.use(Clipboard)
let elementSize = Vue.ls.get(SETTING_ELEMENT_SIZE) || defaultSettings.elementSize;
Vue.use(ElementUI, {size: elementSize}); // set element-ui default size
Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  mounted () {
    store.commit('app/SET_SIDEBAR_HIDE', Vue.ls.get(SETTING_SIDEBAR_STATUS));
    store.commit('app/SET_SIZE', elementSize);
    let themeColor = Vue.ls.get(SETTING_THEME_COLOR);
    initCurTheme(themeColor)
    store.commit('settings/CHANGE_SETTING', {key: SETTING_THEME_COLOR, value: themeColor});
    store.commit('settings/CHANGE_SETTING', {key: SETTING_SIDE_THEME, value: Vue.ls.get(SETTING_SIDE_THEME)});
    store.commit('settings/CHANGE_SETTING', {key: SETTING_TAGS_VIEW, value: Vue.ls.get(SETTING_TAGS_VIEW)});
    store.commit('settings/CHANGE_SETTING', {key: SETTING_FIXED_HEADER, value: Vue.ls.get(SETTING_FIXED_HEADER)});
    store.commit('settings/CHANGE_SETTING', {key: SETTING_SIDEBAR_LOGO, value: Vue.ls.get(SETTING_SIDEBAR_LOGO)});
    store.commit('settings/CHANGE_SETTING', {key: SETTING_DYNAMIC_TITLE, value: Vue.ls.get(SETTING_DYNAMIC_TITLE)});
  },
  render: h => h(App),
  beforeCreate() {
    Vue.prototype.$bus=this; //安装全局事件总线
  }
})
